#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <assert.h>
using namespace std;

namespace ly
{
	class string
	{
	public:
		const static size_t npos;

		friend ostream& operator<<(ostream& _cout, const ly::string& s);
		friend istream& operator>>(istream& _cin, ly::string& s);

		string(const char* str = "");

		string(const string& s);

		ly::string& operator=(const string& s);

		~string();

		typedef char* iterator;
		typedef const char* const_iterator;

		ly::string::iterator begin();
		ly::string::iterator end();

		ly::string::iterator begin() const;
		ly::string::iterator end() const;

		void push_back(char c);
		ly::string& operator+=(char c);
		void append(const char* str);
		ly::string& operator+=(const char* str);
		void clear();
		void swap(ly::string& s);
		const char* c_str();

		size_t size() const;
		size_t capacity() const;
		bool empty() const;
		void resize(size_t n, char c = '\0');
		void reserve(size_t n);

		char& operator[](size_t index);
		const char& operator[](size_t index) const;

		bool operator<(const ly::string& s) const;
		bool operator<=(const ly::string& s) const;
		bool operator>(const ly::string& s) const;
		bool operator>=(const ly::string& s) const;
		bool operator==(const ly::string& s) const;
		bool operator!=(const ly::string& s) const;

		size_t find(char c, size_t pos = 0) const;
		size_t find(const char* s, size_t pos = 0) const;

		ly::string& insert(size_t pos, char c);
		ly::string& insert(size_t pos, const char* str);

		ly::string& erase(size_t pos, size_t len = npos);
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
	};
}
